<?php
/**
 * 部门数据模型
 */

class DepartmentModel extends RelationModel {
	protected $_link = array(
		'session' => array(
			'mapping_type' => BELONGS_TO,
			'class_name' => 'session',
		),
		'posts' => array(
			'mapping_type' => HAS_MANY,
			'class_name' => 'post',
		),
	);

    /** 获取关联成员 */
    protected function _after_find(&$result, $options) {
        parent::_after_find($result, $options);

        $result['members'] = array();
        foreach ($result['posts'] as $post) {
            $post = D('Post')
                ->where(array('id' => $post['id']))
                ->relation(true)
                ->find();
            $result['members'] = array_merge(
                $result['members'],
                $post['members']);
        }
    }
}
